app.register.controller("UsstkAccountCtrl", ["$rootScope", "$scope", "$location", "$timeout", "$window", "ToastMessage", "SecurityService", "FundService", "StockService", function($rootScope, $scope, $location, $timeout, $window, ToastMessage, SecurityService, FundService, StockService) {
    var chartColors = ["#2EC7C9", "#B6A2DE", "#5AB1EF", "#FFB980", "#D87A80", "#8D98B3", "#1E90FA", "#E5CF0D", "#97B552", "#95706D", "#4CAF50"]
      , marketMoney = app.util.getSearch($location, "marketMoney") || 0;
    $scope.marketMoney = marketMoney,
    $scope.getColor = function(index) {
        return chartColors[index % chartColors.length]
    }
    ,
    $scope.formatPercent = function(percent) {
        return percent = percent || 0,
        percent >= 0 ? "+" + percent + "%" : percent + "%"
    }
    ;
    var funs = {
        loadCnstkSummary: function() {
            StockService.summary(8003).success(function(data) {
                data && data.success && ($scope.summary = data.result,
                funs.initChart())
            })
        },
        loadPositions: function() {
            StockService.listPositions(8003).success(function(data) {
                data && data.success ? ($scope.positions = data.result,
                data.result && data.result.list ? $scope.existPositions = data.result.list.length > 0 : $scope.existPositions = !1,
                funs.initChart()) : $scope.existPositions = !1
            })
        },
        initChart: function(t) {
            var qOne = function(sName) {
                return document.querySelector(sName)
            }
              , chartData = [];
            if ($scope.existPositions) {
                var index = 0;
                angular.forEach($scope.positions.list, function(item) {
                    var color = chartColors[index];
                    chartData.push({
                        name: item.stockName,
                        value: item.totalMoney,
                        color: color
                    }),
                    index++
                })
            }
            if (qOne("#ASA_chart")) {
                var config = {
                    series: chartData,
                    root: qOne("#ASA_chart"),
                    unit: "Ԫ",
                    title: "",
                    tooltips: {
                        enable: !1
                    },
                    animation: {
                        enable: !1
                    },
                    legend: {
                        enable: !1
                    },
                    text: {
                        enable: !1
                    }
                };
                pieChart.initSettings(config),
                pieChart.render()
            }
        }
    };
    funs.loadCnstkSummary(),
    funs.loadPositions(),
    funs.initChart()
}
]);
